package org.example.day13;

/**
 * 7.1.3 验证BLOCKED
 *      线程等待锁的时候、
 *      ★注意: ta.start()时，ta的状态由NEW变成RUNNABLE,即使没有获取到CPU资源.
 *      当被锁挡住时，由RUNNABLE变成BLOCKED.一旦获得锁，又变成RUNNABLE.
 */
public class MyThread3 {
    synchronized static public void serviceMethod(){
        try {
            System.out.println(Thread.currentThread().getName() + "进入了业务方法");
            System.out.println("run 方法中的状态: " + Thread.currentThread().getState());
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread3A ta = new Thread3A();
        ta.setName("a");
        ta.start();
        Thread3B tb = new Thread3B();
        tb.setName("B");
        tb.start();
        Thread.sleep(500);
        //main 方法中tb的状态: BLOCKED
        System.out.println("main 方法中tb的状态: " + tb.getState());
    }
}

class Thread3A extends Thread{
    @Override
    public void run() {
        MyThread3.serviceMethod();
    }
}
class Thread3B extends Thread{
    @Override
    public void run() {
        MyThread3.serviceMethod();
    }
}